__name__ = imp.pivot_name
__file__ = imp.pivot_file
__dict__ = globals()
__code__ =  imp.pivot_app[__file__]
__running__ = None
__io__ = []
__print__ = print
import io


def print(*argv,**kw):
    global __print__
    stdio = io.BytesIO()
    if kw.get('file',sys.stdout) is sys.stdout:
        channel = 1;
    else:
        channel = 2;

    kw['file'] = stdio
    __print__(*argv,**kw)
    stdio.seek(0)
    __io__.append( (channel, stdio.read().decode(),) )
    stdio.close()


async def reload():
    global __run__, __io__
    __running__ = True
    __io__.clear()
    try:
        stdio = io.StringIO()
        exec( compile( '\n'.join(__code__) , __file__, 'exec') , __dict__, __dict__)
        __running__ = False
    except Exception as e:
        __print__(__file__, e)
        stdio = io.BytesIO()
        sys.print_exception(e,stdio)
        stdio.seek(0)
        __io__.append( (-1,stdio.read().decode(),) )
        stdio.close()
    try:
        return __io__
    finally:
# BUG: TODO: FIXME: ?
        #__io__.clear()
        pass
